package com.lhq.tag_tales.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
/*
* 表示该配置只在 dev 环境下生效
* */
@Profile({"dev","prod"})
public class Knife4jConfiguration {

    private ApiInfo commonApiInfo() {
        return new ApiInfoBuilder()
                .title("标签物语后端接口测试")
                .description("Knife4j是一款基于Swagger的API文档在线编辑工具.")
                .contact("hwike@foxmail.com")
                .version("1.0")
                .build();
    }

    @Bean(value = "dockerBeanAdmin")
    public Docket dockerBeanAdmin() {
        //指定使用Swagger2规范
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(commonApiInfo())
                //分组名称
                .groupName("标签物语后端接口测试")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.lhq.tag_tales.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    @Bean(value = "dockerBeanFront")
    public Docket dockerBeanFront() {
        //指定使用Swagger2规范
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(commonApiInfo())
                //分组名称
                .groupName("前台接口分组")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.lhq.tag_tales.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
